<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class DetailController extends Controller{
	//声明类的属性
	private $model;
	
	//生命构造方法
	public function __init(){
	    $this->model=new \Common\Model\Goodsattr;
	}
	public function index(){
		//判断是不是有提交
//		if(IS_POST){
//			
//			if($this->model->search()) go(U('shopsuccess'));
//			View::error($this->model->geterror());
//		}
		
		
				
			$gid=Q('get.gid',0,'intval');
			//查出对应的商品信息
			
			$goodsData=M('\Common\Model\Goods')->join('gooddetail','goods_gid','=','gid')->where('goods_gid='.$gid)->find();
			//将商品图图册字段拆分成数组
			$goodsData['gdimg']=explode(',', $goodsData['gdimg']);
			//分配数据	
			//获得所有商品属性的类型属性
				$data=M('\Common\Model\Goodsattr')->join('typeattr','typeattr_taid','=','taid')->where('goods_gid='.$gid.' and tatype=1')->get();
			//按照类型属性分类	
			//将对应的类型属性存的属性拆分成数组
			foreach ($data as $k => $v) {
				$data[$k]['tavalue']=explode(',', $v['tavalue']);
			}
			$arr=array();
			foreach ($data as $k => $v) {
				$arr[$v['taid']][]=$v;
			}
		
			//将组合的数组分配到页面去循环放入
			View::with('arr',$arr);
			View::with('goodsData',$goodsData);
			    View::make();
	}
	//添加购物车成功提示到购物车结算
	public function shopsuccess(){
	    View::make();
	}
	
	//ajax的异步 加入购物车
	public function ajaxcheck(){
	  if($this->model->ajaxcheck()){
	  	echo json_encode(true);	
		 return;	
	  }
	  	
	 echo json_encode(false);
	  exit;
	}
	
}

 ?>